(function (angular) {
    'use strict';
    angular.module('moviecat.movie_detail', ['ngRoute', 'movie.services.http'])
        .config(['$routeProvider', function ($routeProvider) {
            $routeProvider
                .when('/detail/:id', {
                    controller: 'MovieDetailController',
                    templateUrl: 'movie_detail/view.html'
                })
        }])
        .controller('MovieDetailController', [
            '$scope',
            '$route',
            '$routeParams',
            'HttpService',
            function ($scope, $route, $routeParams, HttpService) {
                $scope.movie = {};
                $scope.loading = true;
                $scope.title = 'Loading...';
                HttpService.jsonp('http://api.douban.com/v2//movie/subject' + $routeParams.id,
                    {}, function (data) {
                        $scope.movie = data;
                        $scope.loading = false;
                        $scope.title = data.title;
                        $scope.$apply();//强制同步数据到界面

                    });
                //暴露一个翻页的行为
                $scope.go = function (page) {
                    if (0 < page && page < $scope.totalPage + 1) {
                        $route.updateParams({page: page});
                    }
                }
            }])
})(angular);
